<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>
	<body>
		<input type="button" name="" id="" value="开始" />
		<div id="div" style="width: 50px;height: 50px;background-color: red;position: absolute;">
			
		</div>
		<script>
			var div=document.getElementById('div');
			var i=0;
			var VW=document.documentElement.clientWidth;
			var W=div.offsetWidth;
			setInterval(function(){
				i++;
				console.log(i)
				a=i%(2*(VW-W));
				if(a>VW-W){
				div.style.left =Math.abs(a-2*(VW-W))+'px';	
				}else{
				div.style.left =a+'px';
				console.log(a+'px')	
				}
				
			},1)
			/*setInterval(function(){
				i++;
				console.log(i)
				a=i%1000
				if(a>500){
				div.style.left =Math.abs(a-1000)+'px';	
				}else{
				div.style.left =a+'px';
				console.log(a+'px')	
				}
				
			},10)*/
			
		</script>
	</body>
</html>
